// pages/login/login/account.js
import accountServices, { EVENT_LOGIN } from '../../../services/account'
import userStore from '../../../store/user'
import { USER_INFO } from '../../../constants/user'
let util = require('../../../utils/index');
import Toast from "../../components/toast/toast.js";
import http from '../../../services/http/index'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        multiArray: [['中国', '澳洲'], ['+86', '+61']],
        multiIndex: [0, 0],
        countryCode: '+86',
        form:{
            mobile:'',
            password:''
        }
    },
    handleGetUserInfo({ detail: { errMsg } }) {
        if (errMsg === 'getUserInfo:ok') {
            accountServices.loginByWeixinAsync(() => {
                //accountServices.eventEmitter.emit(EVENT_LOGIN, userStore.getData(USER_INFO));
                console.log('跳转...')
                util.default.go('/pages/orders/index/index', 4)
            })
        }
    },
    bindMultiPickerColumnChange(e) {
        let value = e.detail.value
        this.setData({
            'multiIndex': [value, value]
        })
    },
    bindMultiPickerChange(e) {
        this.setData({
            'countryCode': this.data.multiArray[1][e.detail.value[1]]
        })
    },
    //跳转忘记密码
    gotoForget(){
        util.default.go('../forget/step1/forget1');
    },
    inputBlur(e){
        let value = e.detail.value;
        let type = e.currentTarget.dataset.type;
        let form = this.data.form;
        form[type] = value;
        this.setData({
            form:form
        })
    },
    login(){
        let param = {
            mobile:this.data.form.mobile,
            password:this.data.form.password
        };
        if(param.mobile==''){
            Toast.show(this, 'info', '请输入手机号');
            return false;
        };
        if(param.password==''){
            Toast.show(this, 'info', '请输入密码');
            return false;
        };

        var _this = this;
        accountServices.loginByPhoneNumber(param,_this).then(() => {});
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})